/*
 * @lc app=leetcode.cn id=22 lang=javascript
 *
 * [22] 括号生成
 */

// @lc code=start
/**
 * @param {number} n
 * @return {string[]}
 */
var generateParenthesis = function(n) {
    let res=[]
    let mole="()"
    let dfs=function(str,left,right){
        if(left==n&&right==n){res.push(str); return}
        if(left==n){
            str+=")"
            dfs(str,left,right+1)
        }else if(left>=right){
            dfs(str+"(",left+1,right)
            dfs(str+")",left,right+1)
        }else{
            return
        }
    }
    dfs("(",1,0)
    return res
};
// @lc code=end

